<?php 
require_once '../../config.php';
require_once '../../function.php';
//获取邮箱和密码
$email = $_POST["email"];
$password = $_POST["password"];
//2根据邮箱和密码到数据库中查找有没有对应的数据
//2.1 连接数据库
$connect = connect();
//2.2 准备sql语句
$sql = "SELECT * FROM users WHERE email = '{$email}' and `password` = '{$password}' and `status`='activated'";
//2.3执行sql语句
$queryResult = query($connect,$sql);
//3.判断查询的结果是不是有数据
$response = ["code"=>0,"msg"=>"操作失败"];
if ($queryResult) {
	//如果登录了，应该把登录状态记录一下
	//session
	session_start();
	$_SESSION['isLogin']=1;
	$_SESSION["user_id"]=$queryResult[0]["id"];
    $response["code"]=1;
    $response["msg"] = "登陆成功";
}
//以json格式返回数据
header("content-type:application/json;charset=utf-8");
echo json_encode($response);
 ?>